'''
康爱保疾病保障计划
'''

'''
整理数据
'''
from common.config import *
from db.mysql import MysqlClient

class Arrangement( object ):

    def __init__(self):

        self.mysql = MysqlClient()


    def selectData(self,table,data={}):


        SQL = "SELECT * FROM `"+table+"` WHERE state = 2 "

        self.mysql.cursor.execute( SQL )

        result = self.mysql.cursor.fetchall()

        for item in result:

            data["name"] = table
            data["company"] = "昆仑健康保险"
            data["year"] = item["year"]
            data["gender"] = item["gender"]
            data["expire"] = item["expire"]
            data["interval"] = item["interval"]
            data["money"] = item["money"][::3] + "w"
            data["price"] = item["price"]
            # data["money"] = item["money"] + "w"
            # data["seriousBack"] = item["ext_item"]
            # data["price"] = item["price"]

            self.mergeTable( data )

    # 合并表格
    def mergeTable(self,data):

        SQL = 'INSERT INTO `serious`(`name`,`company`,`year`,`gender`,`expire`,`interval`,`money`,`price`)VALUES("{name}", "{company}", "{year}", "{gender}", "{expire}", "{interval}", "{money}","{price}")'

        self.mysql.cursor.execute(SQL.format(**data))
        self.mysql._conn.commit()

        print( data )

if __name__ == '__main__':

    a = Arrangement()
    name = '康爱保疾病保障计划'
    a.selectData( name )